package no.gnet.edvd.lightweight;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Date;
import java.util.Iterator;
import java.util.List;

import no.gnet.edvd.types.Event;
import no.gnet.edvd.types.EventType;
import no.gnet.edvd.types.GenericEvent;
import no.gnet.edvd.types.Option;
import no.gnet.edvd.types.Player;
import no.gnet.edvd.types.StringOption;

import org.joda.time.DateTime;

public class NewEvent {
	private EventType eventType;
	private String name;
	private String description;
	private Date eventtime;
	private Date betdeadline;
	private Date posted;	
	private Player owner;
	private String category;
	List <StringOption> options;
	boolean privateEvent;
	private List<EmailHolder> invitedList;
	
	public String getName() {
		return name;
	}
	public void setName(String name) {
		this.name = name;
	}
	public String getDescription() {
		return description;
	}
	public void setDescription(String description) {
		this.description = description;
	}
	public Date getEventtime() {
		return eventtime;
	}
	public void setEventtime(Date eventtime) {
		this.eventtime = eventtime;
	}
	public Date getBetdeadline() {
		return betdeadline;
	}
	public void setBetdeadline(Date betdeadline) {
		this.betdeadline = betdeadline;
	}
	public List<StringOption> getOptions() {
		return options;
	}
	public void setOptions(List<StringOption> options) {
		this.options = options;
	}
	public Date getPosted() {
		return posted;
	}
	public void setPosted(Date posted) {
		this.posted = posted;
	}
	public Player getOwner() {
		return owner;
	}
	public void setOwner(Player owner) {
		this.owner = owner;
	}

	public EventType getEventType() {
		return eventType;
	}
	public void setEventType(EventType eventType) {
		this.eventType = eventType;
	}
	

	public Event toEvent() {
		GenericEvent gevent = new GenericEvent();
		gevent.betDeadline=new DateTime(getBetdeadline());
		gevent.description=getDescription();
		gevent.eventPosted=new DateTime(getPosted());
		gevent.eventDecidedTime=new DateTime(getEventtime());
		gevent.eventType=getEventType();
		gevent.name=getName();
		gevent.setOptions(getConvertedOptions());
		gevent.setPrivateEvent(this.privateEvent);
		if(privateEvent)
			gevent.setInvitedList(invitedToEmailStrings());
		return gevent;
	}
	private List<String> invitedToEmailStrings() {
		List<String> ems= new ArrayList<String>();
		for(EmailHolder eh:invitedList){
			ems.add(eh.email);
		}
		return ems;
	}
	private List<Option> getConvertedOptions() {
		List<Option> copts = new ArrayList<Option>();
		List<StringOption> opts = getOptions();
		for (Iterator<StringOption> iterator = opts.iterator(); iterator.hasNext();) {
			StringOption str = iterator.next();
			copts.add(str);
		}
		return copts;
	}
	public String getCategory() {
		return category;
	}
	public void setCategory(String category) {
		this.category = category;
	}
	public boolean isPrivateEvent() {
		return privateEvent;
	}
	public void setPrivateEvent(boolean privateEvent) {
		this.privateEvent = privateEvent;
	}
	public List<EmailHolder> getInvitedList() {
		return invitedList;
	}
	public void setInvitedList(List<EmailHolder> invitedList) {
		this.invitedList = invitedList;
	}

}
